package com.invite.me.beans.adpater;

import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.invite.me.R;
import com.invite.me.beans.res.InformationmyzlBean;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


public class InformationAdpater extends BaseQuickAdapter<InformationmyzlBean.DataBean,BaseViewHolder> {
    private Date date;
    public InformationAdpater(int layoutResId, @Nullable List<InformationmyzlBean.DataBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, InformationmyzlBean.DataBean item) {
        int position = helper.getPosition();
        View view = helper.getView(R.id.xianshiview);
        if(position==0){
            view.setVisibility(View.GONE);
        }
        String cancelTime = item.getCreateTime();
        if(!TextUtils.isEmpty(cancelTime)){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            try {
                date = sdf.parse(cancelTime);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        SimpleDateFormat sdff = new SimpleDateFormat( "yyyy-MM-dd HH:mm" );
        String str = sdff.format(date);
        if(!TextUtils.isEmpty(str)){
            helper.setText(R.id.time,str);
        }
        TextView leixing=helper.getView(R.id.leixing);
        String type = item.getType();
        if(type.equals("0")){
            helper.setText(R.id.name,"未定义");

        }else if(type.equals("1")){
            helper.setText(R.id.name,"相亲");
        }else if(type.equals("2")){
            helper.setText(R.id.name,"找网红");
        }else if(type.equals("3")){
            helper.setText(R.id.name,"找商务");
        }



        final String state = item.getState();





        //0:未支付,1:邀约接受者已确认,2:已支付,3:已完成,4:已支付佣金,50:已退款,100:已取消,101:邀约发起者已取消,102:邀约接受者已取消")

        if(state.equals("0")){
            leixing.setText("待支付");
            leixing.setTextColor(Color.rgb(153,153,153));
            Resources resources = mContext.getResources();
         //   Drawable drawable = resources.getDrawable(R.drawable.huise_type_yuan);
            Drawable drawable = resources.getDrawable(R.drawable.hongse_type_yuan);
            leixing.setBackground(drawable);
        }else if(state.equals("1")){
            leixing.setText("已邀约");
            leixing.setTextColor(Color.rgb(255,255,255));
            Resources resources = mContext.getResources();
            Drawable drawable = resources.getDrawable(R.drawable.chengse_type_yuan);
            leixing.setBackground(drawable);
        }else if(state.equals("2")){
            leixing.setText("已赴约");
            leixing.setTextColor(Color.rgb(255,255,255));
            Resources resources = mContext.getResources();
            Drawable drawable = resources.getDrawable(R.drawable.hongse_type_yuan);
            leixing.setBackground(drawable);
        }else if(state.equals("3")){
            leixing.setText("已完成");
            leixing.setTextColor(Color.rgb(255,255,255));
            Resources resources = mContext.getResources();
            Drawable drawable = resources.getDrawable(R.drawable.shenhui_type_yuan);
            leixing.setBackground(drawable);
        }else if(state.equals("4")){
            leixing.setText("已赴约");
            leixing.setTextColor(Color.rgb(255,255,255));
            Resources resources = mContext.getResources();
            Drawable drawable = resources.getDrawable(R.drawable.shenhui_type_yuan);
            leixing.setBackground(drawable);
        }



        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.xxzw);
        Glide.with(mContext)
                .load(item.getHeadPortrait())
                .apply(options)
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(10)))//圆角半径
                .into((ImageView) helper.getView(R.id.touxiang));
    }
}
